package tests;

import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import calc.Calculator;


public class CalculatorTest {

	private Calculator<Integer> calculatorInteger;
	private Calculator<Double> calculatorDouble;
	private Calculator<Float> calculatorFloat;
	private Calculator<Long> calculatorLong;
	
	
	@Before
	public void setUp() throws Exception {
		this.calculatorInteger = new Calculator<Integer>();
		this.calculatorDouble = new Calculator<Double>();
		this.calculatorFloat = new Calculator<Float>();
		this.calculatorLong = new Calculator<Long>();
	}

	//tests for Integer types. 
	@Test
	public void testAddInteger() {
		Number number = 4;
		Assert.assertTrue(calculatorInteger.add(2, 2).intValue() == number.intValue());	
	}
	
	@Test
	public void testSubtractInteger() {
		Number number = 3;
		Assert.assertTrue(calculatorInteger.subtract(5, 2).intValue() == number.intValue());	
	}
	
	@Test
	public void testMultiplyInteger() {
		Number number = 100;
		Assert.assertTrue(calculatorInteger.multiply(5, 20).intValue() == number.intValue());	
	}
	
	@Test
	public void testDivideInteger() {
		Number number = 2.5;
		Assert.assertTrue(calculatorInteger.divide(5, 2).intValue() == number.intValue());	
	}
	
	//tests for Double types.
	@Test
	public void testAddDouble() {
		Number number = 4.0;
		Assert.assertTrue(calculatorDouble.add(2, 2).doubleValue() == number.doubleValue());	
	}
	
	@Test
	public void testSubtractDouble() {
		Number number = 3.0;
		Assert.assertTrue(calculatorDouble.subtract(5, 2).doubleValue() == number.doubleValue());	
	}
	
	@Test
	public void testMultiplyDouble() {
		Number number = 10.0;
		Assert.assertTrue(calculatorDouble.multiply(4, 2.5).doubleValue() == number.doubleValue());	
	}
	
	@Test
	public void testDivideDouble() {
		Number number = 2.5;
		Assert.assertTrue(calculatorDouble.divide(5, 2).doubleValue() == number.doubleValue());	
	}
	
	//tests for Float types.
	@Test
	public void testAddFloat() {
		Number number = 4.0f;
		Assert.assertTrue(calculatorFloat.add(2f, 2f).floatValue() == number.floatValue());	
	}
	
	@Test
	public void testSubtractFloat() {
		Number number = 3.0f;
		Assert.assertTrue(calculatorFloat.subtract(5f, 2f).floatValue() == number.floatValue());	
	}
	
	@Test
	public void testMultiplyFloat() {
		Number number = 10.0f;
		Assert.assertTrue(calculatorFloat.multiply(4f, 2.5f).floatValue() == number.floatValue());	
	}
	
	@Test
	public void testDivideFloat(){
		Number number = 2.5f;
		Assert.assertTrue(calculatorFloat.divide(5f, 2f).floatValue() == number.floatValue());	
	}
	
	
	//tests for Long types.
	
	@Test
	public void testAddLong() {
		Number number = 40000000000L;
		Assert.assertTrue(calculatorLong.add(30000000000L, 10000000000L).longValue() == number.longValue());	
	}
	
	@Test
	public void testSubtractLong() {
		Number number = 300000000L;
		Assert.assertTrue(calculatorLong.subtract(500000000L, 200000000L).floatValue() == number.floatValue());	
	}
	
	@Test
	public void testMultiplong() {
		Number number = 80000L;
		Assert.assertTrue(calculatorLong.multiply(400L, 200L).floatValue() == number.floatValue());	
	}
	
	@Test
	public void testDivideLong(){
		Number number = 50000L;
		Assert.assertTrue(calculatorLong.divide(100000L, 2L).floatValue() == number.floatValue());	
	}
	
}
